<template>
  <div>
    <h1>添加课程分类</h1>
    <el-form
      status-icon
      ref="teacher"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="信息描述：">
        <el-button type="primary" size="small"
          ><el-link
            :underline="false"
            href="https://fan-guli.oss-cn-beijing.aliyuncs.com/2022/03/22/x1.xlsx"
            >Excel文档示例</el-link
          ></el-button
        >
      </el-form-item>

      <el-form-item label="选择Excel:">
        <el-upload
          class="upload-demo"
          drag
          :action="BASE_API + '/eduService/subject/uploadExcel'"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          filed="file"
          :before-upload="beforeAvatarUpload"
          multiple
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">
            只能上传xlsx格式的文件
          </div>
        </el-upload>
      </el-form-item>
      <el-form-item><template></template></el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      BASE_API: process.env.VUE_APP_BASE_API,
    };
  },
  methods: {
    //文件上传成功执行
    handleAvatarSuccess(res, file) {
        if(res.code===20000){
            this.$message.success("上传成功！！")
            this.$router.push('/subject/table')
        }else{
            this.$message.error(res.message)
        }
    },
    beforeAvatarUpload(file) {
      const isXlsx = file.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
      if (!isXlsx) {
        this.$message.error("上传只能是xlsx格式!");
      }
      return isXlsx;
    },
  },
};
</script>

<style>
</style>